using UnityEditor;
using UnityEngine;

namespace EditorExtension
{
    public class MenuItemExample
    {
        [MenuItem("EditorExtensions/01_Menu/01_Hello Editor")]
        static void HelloEditor()
        {
            Debug.Log("Hello Editor");
        }
        
        [MenuItem("EditorExtensions/01_Menu/02_Open Bilibili")]
        static void OpenBilibili()
        {
            Application.OpenURL("https://bilibili.com/");
        }
        
        [MenuItem("EditorExtensions/01_Menu/03_Open Persistent Data Path")]
        static void OpenPersistentDataPath()
        {
            EditorUtility.RevealInFinder(Application.persistentDataPath);
        }

        [MenuItem("EditorExtensions/01_Menu/04_Open Library Folder")]
        static void OpenLibraryFolder()
        {
            Debug.Log(Application.dataPath);
            EditorUtility.RevealInFinder(Application.dataPath.Replace("Assets", "Library"));       
        }
        
        private static bool mToggleShotCut = false;
        [MenuItem("EditorExtensions/01_Menu/05_Toggle ShotCut")]
        static void ToggleShotCut()
        {
            mToggleShotCut = !mToggleShotCut;
            Menu.SetChecked("EditorExtensions/01_Menu/05_Toggle ShotCut", mToggleShotCut);
        }
        
        /*
         * 自定义快捷键：
         *      # shift
         *      % ctrl
         *      & alt
         *      _a-zA-Z a-zA-Z
         */
        [MenuItem("EditorExtensions/01_Menu/06_Hello Editor With ShotCut _c")]
        static void HelloEditorWithShotCut()
        {
            Debug.Log("Hello Editor");
        }
        
        [MenuItem("EditorExtensions/01_Menu/07_Open Bilibili With ShotCut %e")]
        static void OpenBilibiliWithShotCut()
        {
            Application.OpenURL("https://bilibili.com/");
        }
        
        [MenuItem("EditorExtensions/01_Menu/08_Open Persistent Data Path With ShotCut %#t")]
        static void OpenPersistentDataPathWithShotCut()
        {
            EditorUtility.RevealInFinder(Application.persistentDataPath);
        }
        
        [MenuItem("EditorExtensions/01_Menu/09_Open Library Folder With ShotCut &r")]
        static void OpenLibraryFolderWithShotCut()
        {
            Debug.Log(Application.dataPath);
            EditorUtility.RevealInFinder(Application.dataPath.Replace("Assets", "Library"));       
        }
        
        /*
         * 为菜单项添加验证方法
         */
        [MenuItem("EditorExtensions/01_Menu/06_Hello Editor With ShotCut _c", true)]
        static bool HelloEditorWithShotCutValidate()
        {
            return mToggleShotCut;
        }
        
        [MenuItem("EditorExtensions/01_Menu/07_Open Bilibili With ShotCut %e", true)]
        static bool OpenBilibiliWithShotCutValidate()
        {
            return mToggleShotCut;
        }
        
        [MenuItem("EditorExtensions/01_Menu/08_Open Persistent Data Path With ShotCut %#t", true)]
        static bool OpenPersistentDataPathWithShotCutValidate()
        {
            return mToggleShotCut;
        }
        
        [MenuItem("EditorExtensions/01_Menu/09_Open Library Folder With ShotCut &r", true)]
        static bool OpenLibraryFolderWithShotCutValidate()
        {
            return mToggleShotCut;
        }
        
        /*
         * 菜单项复用
         */
        [MenuItem("EditorExtensions/01_Menu/10_Open Library Folder With ShotCut2")]
        static void OpenLibraryFolderWithShotCut2()
        {
            EditorApplication.ExecuteMenuItem("EditorExtensions/01_Menu/04_Open Library Folder");
        }
    }
}
